<html>
<head><meta charset="utf-8"><title>Projection sub-obligation caching · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Projection.20sub-obligation.20caching.html">Projection sub-obligation caching</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="240880261"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Projection%20sub-obligation%20caching/near/240880261" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Projection.20sub-obligation.20caching.html#240880261">(May 31 2021 at 23:52)</a>:</h4>
<p>Currently, when we cache the result of a projection , we try to discard as many of the sub-obligations as we can: <a href="https://github.com/rust-lang/rust/blob/657bc01888e6297257655585f9c475a0801db6d2/compiler/rustc_trait_selection/src/traits/project.rs#L608">https://github.com/rust-lang/rust/blob/657bc01888e6297257655585f9c475a0801db6d2/compiler/rustc_trait_selection/src/traits/project.rs#L608</a></p>
<p>However, this interacts badly with incremental compilation. If one of the sub-obligations ends up evaluating to <code>EvaluatedToOkModuloRegions</code>, then an uncached evaluation of the predicate will also evaluate to <code>EvaluatedToOkModuloRegions</code>. If that sub-obligation gets thrown away when the projection result is cached, subsequent evaluations involving that projection can evaluate to <code>EvaluateToOk</code>. Since the cache is not saved across compilation sessions, the next compilation session will perform an uncached evaluation of that projection, resulting in <code>EvalutedToOkModuloRegions</code></p>
<p>The simplest solution would be always cache all sub-obligations, and never discard any subobligations. I attempted this in <a href="https://github.com/rust-lang/rust/pull/85868">https://github.com/rust-lang/rust/pull/85868</a> ,but there were some significant perf regressions. Does anyone have any ideas for a way to perform caching here that's compatible with incremental compilation?</p>
<p>cc <span class="user-group-mention" data-user-group-id="3282">@wg-incr-comp</span></p>



<a name="240880368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Projection%20sub-obligation%20caching/near/240880368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Projection.20sub-obligation.20caching.html#240880368">(May 31 2021 at 23:55)</a>:</h4>
<p>Unfortunately, we can't know in advance if a particular sub-obligation will lead to <code>EvalutedToOkModuloRegion</code></p>



<a name="240880400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Projection%20sub-obligation%20caching/near/240880400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Projection.20sub-obligation.20caching.html#240880400">(May 31 2021 at 23:56)</a>:</h4>
<p>as there could be a lifetime-related predicate that occurs at an arbitrary depth</p>



<a name="240929536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Projection%20sub-obligation%20caching/near/240929536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mw <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Projection.20sub-obligation.20caching.html#240929536">(Jun 01 2021 at 11:50)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> might have an idea who would know about this kind of thing</p>



<a name="241147158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Projection%20sub-obligation%20caching/near/241147158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Projection.20sub-obligation.20caching.html#241147158">(Jun 02 2021 at 13:20)</a>:</h4>
<p>We should discuss this in <a class="stream" data-stream-id="144729" href="/#narrow/stream/144729-wg-traits">#wg-traits</a></p>



<a name="241147173"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Projection%20sub-obligation%20caching/near/241147173" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Projection.20sub-obligation.20caching.html#241147173">(Jun 02 2021 at 13:20)</a>:</h4>
<p>There is a pending PR to remove that logic altogether</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>